package com.allnas.springcloud.web;

import com.allnas.springcloud.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaojin
 */
@Slf4j
@RestController
public class IndexController {

    @GetMapping("query/{id}")
    public User query(@PathVariable Integer id, @RequestParam(value = "type", required = false, defaultValue = "") String type) {
        log.info("type:{}", type);
        User user = new User();
        user.setId(id);
        user.setName("学习" + id);
        user.setPassword("123456" + type);
        return user;
    }

    @PostMapping("check")
    public String check(@RequestBody User user) {
        log.info("user:{}", user);
        return "admin".equals(user.getName()) ? "管理员" : "普通用户";
    }
}
